﻿using Domain.Production_Modules;
using Infratructure.Interface;
using MediatR;
using MES.Server.API.Application.Command.InvoiceTicket.order;
using MES.Server.API.Application.Command.Production_Modules.Pulldown;
using MES.Server.API.Dto.Warehouse;
using Microsoft.EntityFrameworkCore;
using ReturnValue;

namespace MES.Server.API.Application.Handler.InvoiceTicket.Order
{
    public class OrderQueryCommandHandler : IRequestHandler<GetOrderQueryCommand, ApiPaging<OrderModel>>
    {
        IRepository<OrderModel> repository;
        public OrderQueryCommandHandler(IRepository<OrderModel> repository)
        {
            this.repository = repository;
        }
        public async Task<ApiPaging<OrderModel>> Handle(GetOrderQueryCommand request, CancellationToken cancellationToken)
        {
            var list= repository.GetAll().Where(x=>!x.IsDel);
            ApiPaging<OrderModel> ping = new ApiPaging<OrderModel>();
            ping.Totalcount=await list.CountAsync();
            ping.Code = StatusCode.Success;
            ping.Message = "查询成功";
            ping.TotalPage = await list.OrderByDescending(x => x.Id).Skip((request.Index - 1) * request.Size).Take(request.Size).ToListAsync();
            return ping;

        }
    }
}
